<!DOCTYPE html>
<html lang="zh-tw">
<head prefix="og: http://ogp.me/ns#">
  <meta charset="utf-8">
  <title>外掛 | Hexo</title>
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <!-- Canonical links -->
  <link rel="canonical" href="https://hexo.io/zh-tw/docs/plugins.html">
  <!-- Alternative links -->
  
    
      <link rel="alternative" hreflang="en" href="https://hexo.io/docs/plugins.html">
    
      <link rel="alternative" hreflang="zh-tw" href="https://hexo.io/zh-tw/docs/plugins.html">
    
      <link rel="alternative" hreflang="zh-cn" href="https://hexo.io/zh-cn/docs/plugins.html">
    
      <link rel="alternative" hreflang="ru" href="https://hexo.io/ru/docs/plugins.html">
    
      <link rel="alternative" hreflang="ko" href="https://hexo.io/ko/docs/plugins.html">
    
  
  <!-- Icon -->
  <link rel="apple-touch-icon" sizes="57x57" href="/icon/apple-touch-icon-57x57.png">
  <link rel="apple-touch-icon" sizes="114x114" href="/icon/apple-touch-icon-114x114.png">
  <link rel="apple-touch-icon" sizes="72x72" href="/icon/apple-touch-icon-72x72.png">
  <link rel="apple-touch-icon" sizes="144x144" href="/icon/apple-touch-icon-144x144.png">
  <link rel="apple-touch-icon" sizes="60x60" href="/icon/apple-touch-icon-60x60.png">
  <link rel="apple-touch-icon" sizes="120x120" href="/icon/apple-touch-icon-120x120.png">
  <link rel="apple-touch-icon" sizes="76x76" href="/icon/apple-touch-icon-76x76.png">
  <link rel="apple-touch-icon" sizes="152x152" href="/icon/apple-touch-icon-152x152.png">
  <link rel="icon" type="image/png" href="/icon/favicon-196x196.png" sizes="196x196">
  <link rel="icon" type="image/png" href="/icon/favicon-160x160.png" sizes="160x160">
  <link rel="icon" type="image/png" href="/icon/favicon-96x96.png" sizes="96x96">
  <link rel="icon" type="image/png" href="/icon/favicon-16x16.png" sizes="16x16">
  <link rel="icon" type="image/png" href="/icon/favicon-32x32.png" sizes="32x32">
  <meta name="msapplication-TileColor" content="#2f83cd">
  <meta name="msapplication-TileImage" content="/icon/mstile-144x144.png">
  <!-- CSS -->
  <!-- build:css build/css/navy.css -->
  <link rel="stylesheet" href="/css/navy.css">
  <!-- endbuild -->
  <link href="https://fonts.googleapis.com/css?family=Lato:300,400,700" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.css">
  <!-- RSS -->
  <link rel="alternate" href="/atom.xml" title="Hexo">
  <!-- Open Graph -->
  <meta name="description" content="Hexo 有強大的外掛系統，使您能輕鬆擴展功能而不用修改核心模組的原始碼。在 Hexo 中有兩種形式的外掛： 腳本（Scripts）如果您的程式碼很簡單，建議您撰寫腳本，您只需要把 JavaScript 檔案放到 scripts 資料夾，在啟動時就會自動載入一次。 套件（Packages）如果您的程式碼較複雜，或是您想要發佈到 NPM 上，建議您撰寫套件。首先，在 node_modules 資料夾">
<meta property="og:type" content="website">
<meta property="og:title" content="外掛">
<meta property="og:url" content="https://hexo.io/zh-tw/docs/plugins.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Hexo 有強大的外掛系統，使您能輕鬆擴展功能而不用修改核心模組的原始碼。在 Hexo 中有兩種形式的外掛： 腳本（Scripts）如果您的程式碼很簡單，建議您撰寫腳本，您只需要把 JavaScript 檔案放到 scripts 資料夾，在啟動時就會自動載入一次。 套件（Packages）如果您的程式碼較複雜，或是您想要發佈到 NPM 上，建議您撰寫套件。首先，在 node_modules 資料夾">
<meta property="og:locale" content="zh-tw">
<meta property="og:updated_time" content="2017-12-06T21:52:16.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="外掛">
<meta name="twitter:description" content="Hexo 有強大的外掛系統，使您能輕鬆擴展功能而不用修改核心模組的原始碼。在 Hexo 中有兩種形式的外掛： 腳本（Scripts）如果您的程式碼很簡單，建議您撰寫腳本，您只需要把 JavaScript 檔案放到 scripts 資料夾，在啟動時就會自動載入一次。 套件（Packages）如果您的程式碼較複雜，或是您想要發佈到 NPM 上，建議您撰寫套件。首先，在 node_modules 資料夾">
<meta name="twitter:site" content="hexojs">
<meta property="fb:admins" content="100000247608790">
  <!-- Google Analytics -->
  
<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-48498357-3', 'auto');
  ga('send', 'pageview');
</script>

</head>

<body>
  <div id="container">
    <header id="header" class="wrapper">
  <div id="header-inner" class="inner">
    <h1 id="logo-wrap">
      <a href="/zh-tw/" id="logo">Hexo</a>
    </h1>
    <nav id="main-nav">
      <a href="/zh-tw/docs/" class="main-nav-link">文件</a><a href="/zh-tw/api/" class="main-nav-link">API</a><a href="/news/" class="main-nav-link">新聞</a><a href="/plugins/" class="main-nav-link">外掛</a><a href="/themes/" class="main-nav-link">主題</a>
      <a href="https://github.com/hexojs/hexo" class="main-nav-link"><i class="fa fa-github-alt"></i></a>
      <div id="search-input-wrap">
        <div id="search-input-icon">
          <i class="fa fa-search"></i>
        </div>
        <input type="search" id="search-input" placeholder="Search...">
      </div>
    </nav>
    <div id="lang-select-wrap">
      <label id="lang-select-label"><i class="fa fa-globe"></i><span>正體中文</span></label>
      <select id="lang-select" data-canonical="docs/plugins.html">
        
          <option value="en">English</option>
        
          <option value="zh-tw" selected>正體中文</option>
        
          <option value="zh-cn">简体中文</option>
        
          <option value="ru">Русский</option>
        
          <option value="ko">한국어</option>
        
      </select>
    </div>
    <a id="mobile-nav-toggle">
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
      <span class="mobile-nav-toggle-bar"></span>
    </a>
  </div>
</header>

    <div id="content-wrap">
  <div id="content" class="wrapper">
    <div id="content-inner">
      <article class="article-container" itemscope itemtype="http://schema.org/Article">
        <div class="article-inner">
          <div class="article">
            <div class="inner">
              <header class="article-header">
                <h1 class="article-title" itemprop="name">外掛</h1>
                <a href="https://github.com/hexojs/site/edit/master/source/zh-tw/docs/plugins.md" class="article-edit-link" title="改善這篇文件"><i class="fa fa-pencil"></i></a>
              </header>
              <div class="article-content" itemprop="articleBody">
                <p>Hexo 有強大的外掛系統，使您能輕鬆擴展功能而不用修改核心模組的原始碼。在 Hexo 中有兩種形式的外掛：</p>
<h3 id="腳本（Scripts）" class="article-heading"><a href="#腳本（Scripts）" class="headerlink" title="腳本（Scripts）"></a>腳本（Scripts）<a class="article-anchor" href="#腳本（Scripts）" aria-hidden="true"></a></h3><p>如果您的程式碼很簡單，建議您撰寫腳本，您只需要把 JavaScript 檔案放到 <code>scripts</code> 資料夾，在啟動時就會自動載入一次。</p>
<h3 id="套件（Packages）" class="article-heading"><a href="#套件（Packages）" class="headerlink" title="套件（Packages）"></a>套件（Packages）<a class="article-anchor" href="#套件（Packages）" aria-hidden="true"></a></h3><p>如果您的程式碼較複雜，或是您想要發佈到 NPM 上，建議您撰寫套件。首先，在 <code>node_modules</code> 資料夾中建立資料夾，資料夾名稱開頭必須為 <code>hexo-</code>，如此一來 Hexo 才會在啟動時載入。</p>
<p>資料夾內至少要包含 2 個檔案：一個是主程式，另一個是 <code>package.json</code>，描述套件的用途和相依套件。</p>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">.</span><br><span class="line">├── index.js</span><br><span class="line">└── package.json</span><br></pre></td></tr></table></figure>
<p><code>package.json</code> 中至少要包含 <code>name</code>, <code>version</code>, <code>main</code> 屬性，例如：</p>
<figure class="highlight json"><figcaption><span>package.json</span></figcaption><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="attr">"name"</span>: <span class="string">"hexo-my-plugin"</span>,</span><br><span class="line">  <span class="attr">"version"</span>: <span class="string">"0.0.1"</span>,</span><br><span class="line">  <span class="attr">"main"</span>: <span class="string">"index"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="工具" class="article-heading"><a href="#工具" class="headerlink" title="工具"></a>工具<a class="article-anchor" href="#工具" aria-hidden="true"></a></h3><p>您可善用 Hexo 提供的官方工具套件來加速開發：</p>
<ul>
<li><a href="https://github.com/hexojs/hexo-fs" target="_blank" rel="noopener">hexo-fs</a>：檔案 IO</li>
<li><a href="https://github.com/hexojs/hexo-util" target="_blank" rel="noopener">hexo-util</a>：工具程式</li>
<li><a href="https://github.com/hexojs/hexo-i18n" target="_blank" rel="noopener">hexo-i18n</a>：本地化（i18n）</li>
<li><a href="https://github.com/hexojs/hexo-pagination" target="_blank" rel="noopener">hexo-pagination</a>：產生分頁資料</li>
</ul>
<h3 id="發佈" class="article-heading"><a href="#發佈" class="headerlink" title="發佈"></a>發佈<a class="article-anchor" href="#發佈" aria-hidden="true"></a></h3><p>當您完成外掛後，可以考慮將它發佈到 <a href="/plugins">外掛列表</a>，讓更多人能夠使用您的外掛。發佈外掛的步驟和 <a href="contributing.html#更新文件">更新文件</a> 非常類似。</p>
<ol>
<li>Fork <a href="https://github.com/hexojs/site" target="_blank" rel="noopener">hexojs/site</a></li>
<li><p>把檔案庫（repository）複製到電腦上，並安裝相依套件。</p>
 <figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">$ git clone https://github.com/&lt;username&gt;/site.git</span><br><span class="line">$ cd site</span><br><span class="line">$ npm install</span><br></pre></td></tr></table></figure>
</li>
<li><p>編輯 <code>source/_data/plugins.yml</code>，在檔案中新增您的外掛，例如：</p>
 <figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">- name: hexo-server</span><br><span class="line">  description: Server module for Hexo.</span><br><span class="line">  link: https://github.com/hexojs/hexo-server</span><br><span class="line">  tags:</span><br><span class="line">    - official</span><br><span class="line">    - server</span><br><span class="line">    - console</span><br></pre></td></tr></table></figure>
</li>
<li><p>推送（push）分支。</p>
</li>
<li>建立一個新的合併申請（pull request）。</li>
</ol>

              </div>
              <footer class="article-footer">
                <time class="article-footer-updated" datetime="2017-12-06T21:52:16.000Z" itemprop="dateModified">上次更新：2017-12-06</time>
                <a href="internationalization.html" class="article-footer-prev" title="國際化 (i18n)"><i class="fa fa-chevron-left"></i><span>上一頁</span></a><a href="troubleshooting.html" class="article-footer-next" title="解決問題"><span>下一頁</span><i class="fa fa-chevron-right"></i></a>
              </footer>
              
<section id="comments">
  <div id="disqus_thread"></div>
</section>
<script>
  var disqus_shortname = 'hexojs';
  var disqus_url = 'https://hexo.io/zh-tw/docs/plugins.html';
  var disqus_title = "外掛";
  var disqus_config = function(){
    this.language = 'zh_TW';
  };
  (function(){
    var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
    dsq.src = 'https://go.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  })();
</script>

            </div>
          </div>
          <aside id="article-toc" role="navigation">
            <div id="article-toc-inner">
              <script async type="text/javascript" src="//cdn.carbonads.com/carbon.js?zoneid=1673&serve=C6AILKT&placement=hexoio" id="_carbonads_js"></script>
              <strong class="sidebar-title">目錄</strong>
              <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#腳本（Scripts）"><span class="toc-text"><a href="#&#x8173;&#x672C;&#xFF08;Scripts&#xFF09;" class="headerlink" title="&#x8173;&#x672C;&#xFF08;Scripts&#xFF09;"></a>&#x8173;&#x672C;&#xFF08;Scripts&#xFF09;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#套件（Packages）"><span class="toc-text"><a href="#&#x5957;&#x4EF6;&#xFF08;Packages&#xFF09;" class="headerlink" title="&#x5957;&#x4EF6;&#xFF08;Packages&#xFF09;"></a>&#x5957;&#x4EF6;&#xFF08;Packages&#xFF09;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#工具"><span class="toc-text"><a href="#&#x5DE5;&#x5177;" class="headerlink" title="&#x5DE5;&#x5177;"></a>&#x5DE5;&#x5177;</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#發佈"><span class="toc-text"><a href="#&#x767C;&#x4F48;" class="headerlink" title="&#x767C;&#x4F48;"></a>&#x767C;&#x4F48;</span></a></li></ol>
              <a href="#" id="article-toc-top">回到頁首</a>
            </div>
          </aside>
        </div>
      </article>
      <aside id="sidebar" role="navigation">
  <div class="inner">
    <strong class="sidebar-title">開始使用</strong><a href="index.html" class="sidebar-link">概覽</a><a href="setup.html" class="sidebar-link">建立</a><a href="configuration.html" class="sidebar-link">配置</a><a href="commands.html" class="sidebar-link">指令</a><a href="migration.html" class="sidebar-link">轉移</a><strong class="sidebar-title">基本操作</strong><a href="writing.html" class="sidebar-link">寫作</a><a href="front-matter.html" class="sidebar-link">Front-matter</a><a href="tag-plugins.html" class="sidebar-link">標籤外掛</a><a href="asset-folders.html" class="sidebar-link">資產資料夾</a><a href="data-files.html" class="sidebar-link">資料檔案</a><a href="server.html" class="sidebar-link">伺服器</a><a href="generating.html" class="sidebar-link">產生檔案</a><a href="deployment.html" class="sidebar-link">佈署</a><strong class="sidebar-title">自定</strong><a href="permalinks.html" class="sidebar-link">永久連結</a><a href="themes.html" class="sidebar-link">主題</a><a href="templates.html" class="sidebar-link">模版</a><a href="variables.html" class="sidebar-link">變數</a><a href="helpers.html" class="sidebar-link">輔助函數</a><a href="internationalization.html" class="sidebar-link">國際化 (i18n)</a><a href="plugins.html" class="sidebar-link current">外掛</a><strong class="sidebar-title">其他</strong><a href="troubleshooting.html" class="sidebar-link">解決問題</a><a href="contributing.html" class="sidebar-link">貢獻</a>
  </div>
</aside>
    </div>
  </div>
</div>

    <footer id="footer" class="wrapper">
  <div class="inner">
    <div id="footer-copyright">
      &copy; 2017 <a href="https://github.com/hexojs/hexo/graphs/contributors" target="_blank">Hexo</a><br>
      Documentation licensed under <a href="http://creativecommons.org/licenses/by/4.0/" target="_blank">CC BY 4.0</a>.
    </div>
    <div id="footer-links">
      <a href="https://twitter.com/hexojs" class="footer-link" target="_blank"><i class="fa fa-twitter"></i></a>
      <a href="https://github.com/hexojs/hexo" class="footer-link" target="_blank"><i class="fa fa-github-alt"></i></a>
    </div>
  </div>
</footer>

  </div>
  <div id="mobile-nav-dimmer"></div>
  <nav id="mobile-nav">
  <div id="mobile-nav-inner">
    <ul id="mobile-nav-list">
      <a href="/zh-tw/docs/" class="mobile-nav-link">文件</a><a href="/zh-tw/api/" class="mobile-nav-link">API</a><a href="/news/" class="mobile-nav-link">新聞</a><a href="/plugins/" class="mobile-nav-link">外掛</a><a href="/themes/" class="mobile-nav-link">主題</a>
      <li class="mobile-nav-item">
        <a href="https://github.com/hexojs/hexo" class="mobile-nav-link" rel="external" target="_blank">GitHub</a>
      </li>
    </ul>
    
      <strong class="mobile-nav-title">開始使用</strong><a href="index.html" class="mobile-nav-link">概覽</a><a href="setup.html" class="mobile-nav-link">建立</a><a href="configuration.html" class="mobile-nav-link">配置</a><a href="commands.html" class="mobile-nav-link">指令</a><a href="migration.html" class="mobile-nav-link">轉移</a><strong class="mobile-nav-title">基本操作</strong><a href="writing.html" class="mobile-nav-link">寫作</a><a href="front-matter.html" class="mobile-nav-link">Front-matter</a><a href="tag-plugins.html" class="mobile-nav-link">標籤外掛</a><a href="asset-folders.html" class="mobile-nav-link">資產資料夾</a><a href="data-files.html" class="mobile-nav-link">資料檔案</a><a href="server.html" class="mobile-nav-link">伺服器</a><a href="generating.html" class="mobile-nav-link">產生檔案</a><a href="deployment.html" class="mobile-nav-link">佈署</a><strong class="mobile-nav-title">自定</strong><a href="permalinks.html" class="mobile-nav-link">永久連結</a><a href="themes.html" class="mobile-nav-link">主題</a><a href="templates.html" class="mobile-nav-link">模版</a><a href="variables.html" class="mobile-nav-link">變數</a><a href="helpers.html" class="mobile-nav-link">輔助函數</a><a href="internationalization.html" class="mobile-nav-link">國際化 (i18n)</a><a href="plugins.html" class="mobile-nav-link current">外掛</a><strong class="mobile-nav-title">其他</strong><a href="troubleshooting.html" class="mobile-nav-link">解決問題</a><a href="contributing.html" class="mobile-nav-link">貢獻</a>
    
  </div>
  <div id="mobile-lang-select-wrap">
    <span id="mobile-lang-select-label"><i class="fa fa-globe"></i><span>正體中文</span></span>
    <select id="mobile-lang-select" data-canonical="docs/plugins.html">
      
        <option value="en">English</option>
      
        <option value="zh-tw" selected>正體中文</option>
      
        <option value="zh-cn">简体中文</option>
      
        <option value="ru">Русский</option>
      
        <option value="ko">한국어</option>
      
    </select>
  </div>
</nav>
  <!-- Scripts -->
<!-- build:js build/js/main.js -->
<script src="/js/lang_select.js"></script>
<script src="/js/toc.js"></script>
<script src="/js/mobile_nav.js"></script>
<!-- endbuild -->

<!-- Algolia -->

<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script type="text/javascript">
document.getElementById('search-input-wrap').classList.add('on');
docsearch({
  apiKey: 'c83d2ec3440f40aec6d0e695ecec7ef3',
  indexName: 'hexo_zh-tw',
  inputSelector: '#search-input'
});
</script>


</body>
</html>